<template>
  <div class="goods">
    <div v-loading="loading" element-loading-text="加载中..." style="min-height: 35vw;">
      <div class="img-item" v-if="!noResult">
        <!--商品-->
        <div class="goods-box w">
          <mall-maker v-for="(item,i) in makers" :key="i" :msg="item"></mall-maker>
        </div>
        <el-pagination
          v-if="!noResult&&!error"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[8, 16, 40]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalCount">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import makerApi from '@/api/maker'
import YButton from '@/components/YButton'
import mallMaker from '@/components/mallMaker'

export default {
  data() {
    return {
      makers: [],//制作人列表
      currentPage: 1,//页码
      pageSize: 8,//每页记录数
      totalCount: 0,//总记录数
      noResult: false,
      error: false,
      loading: true,
    }
  },

  created() {
    this.fetchData()
  },

  methods: {
    handleSizeChange (val) {
        this.pageSize = val
        this.fetchData()
        this.loading = true
      },
    handleCurrentChange (val) {
        this.currentPage = val
        this.fetchData()
        this.loading = true
      },

    fetchData() {
      let params = {
           page: this.currentPage,
           limit: this.pageSize
        }
      makerApi.makerList(params).then(response => {
        this.makers = response.page.list
        this.totalCount = response.page.totalCount

        if (response.code === 0) {
          this.noResult = false
          if (this.makers === null) {
            this.noResult = true
          }
          this.error = false
        } else {
          this.error = true
        }
        this.loading = false
      })
    }
  },
  components: {
    YButton,
    mallMaker
  }

}
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
  @import "../../assets/style/mixin";
  @import "../../assets/style/theme";

  .nav {
    height: 60px;
    line-height: 60px;
    > div {
      display: flex;
      align-items: center;
      a {
        padding: 0 15px;
        height: 100%;
        @extend %block-center;
        font-size: 12px;
        color: #999;
        &.active {
          color: #5683EA;
        }
        &:hover {
          color: #5683EA;
        }
      }
      input {
        @include wh(80px, 30px);
        border: 1px solid #ccc;
      }
      input + input {
        margin-left: 10px;
      }
    }
    .price-interval {
      padding: 0 15px;
      @extend %block-center;
      input[type=number] {
        border: 1px solid #ccc;
        text-align: center;
        background: none;
        border-radius: 5px;
      }
    }
  }

  .goods-box {
    > div {
      float: left;
      border: 1px solid #efefef;
    }
  }

  .no-info {
    padding: 100px 0;
    text-align: center;
    font-size: 30px;
    display: flex;
    flex-direction: column;
    .no-data{
      align-self: center;
    }
  }

  .img-item{
    display: flex;
    flex-direction: column;
  }

  .el-pagination{
    align-self: flex-end;
    margin: 3vw 10vw 2vw;
  }

  .section {
    padding-top: 8vw;
    margin-bottom: -5vw;
    width: 1218px;
    align-self: center;
  }

  .recommend {
    display: flex;
    > div {
      flex: 1;
      width: 25%;
    }
  }
</style>
